import { ElLoading } from 'element-plus'

let loadingInstance: ReturnType<typeof ElLoading.service> | null = null

/**
 * 显示全局 loading
 * @param text loading 文本
 */
export function showLoading(text = '加载中...',background = 'rgba(255,255,255,0.6)') {
  if (!loadingInstance) {
    loadingInstance = ElLoading.service({
      lock: true,
      text,
      background
    })
  }
}

/**
 * 关闭全局 loading
 */
export function hideLoading() {
  if (loadingInstance) {
    loadingInstance.close()
    loadingInstance = null
  }
}